/******************************************************************************/
/*                                                                            */
/*  Copyright (c) 2009: ngi-central.org                                       */
/*  All rights reserved.                                                      */
/*                                                                            */
/******************************************************************************/


#include <boost/test/unit_test.hpp>

#include "..\..\include\sgl\line.h"

BOOST_AUTO_TEST_SUITE( line3d )


BOOST_AUTO_TEST_CASE( line3d__default_constructor )
{
	sgl::line<3> a;

	BOOST_CHECK( a.origin()[0] == 0 );
	BOOST_CHECK( a.origin()[1] == 0 );
	BOOST_CHECK( a.origin()[2] == 0 );
	BOOST_CHECK( a.direction()[0] == 0 );
	BOOST_CHECK( a.direction()[1] == 0 );

	sgl::line<3> b(
		sgl::point<3>(1, 2, 3),
		sgl::direction<3>(4, 5));

	BOOST_CHECK( b.origin()[0] == 1 );
	BOOST_CHECK( b.origin()[1] == 2 );
	BOOST_CHECK( b.origin()[2] == 3 );
	BOOST_CHECK( b.direction()[0] == 4 );
	BOOST_CHECK( b.direction()[1] == 5 );
}

BOOST_AUTO_TEST_CASE( line3d__copy_constructor )
{
	sgl::line<3> a(sgl::line<3>(
		sgl::point<3>(1, 2, 3),
		sgl::direction<3>(4, 5)));

	BOOST_CHECK( a.origin()[0] == 1 );
	BOOST_CHECK( a.origin()[1] == 2 );
	BOOST_CHECK( a.origin()[2] == 3 );
	BOOST_CHECK( a.direction()[0] == 4 );
	BOOST_CHECK( a.direction()[1] == 5 );
}

BOOST_AUTO_TEST_CASE( line3d__copy_assignment )
{
	sgl::line<3> a;
	a = sgl::line<3>(
			sgl::point<3>(1, 2, 3),
			sgl::direction<3>(4, 5));

	BOOST_CHECK( a.origin()[0] == 1 );
	BOOST_CHECK( a.origin()[1] == 2 );
	BOOST_CHECK( a.origin()[2] == 3 );
	BOOST_CHECK( a.direction()[0] == 4 );
	BOOST_CHECK( a.direction()[1] == 5 );
}

BOOST_AUTO_TEST_CASE( line3d__swap )
{
	sgl::line<3> a(sgl::line<3>(
		sgl::point<3>(1, 2, 3),
		sgl::direction<3>(4, 5)));
	sgl::line<3> b;

	a.swap(b);

	BOOST_CHECK( a.origin()[0] == 0 );
	BOOST_CHECK( a.origin()[1] == 0 );
	BOOST_CHECK( a.origin()[2] == 0 );
	BOOST_CHECK( a.direction()[0] == 0 );
	BOOST_CHECK( a.direction()[1] == 0 );
	BOOST_CHECK( b.origin()[0] == 1 );
	BOOST_CHECK( b.origin()[1] == 2 );
	BOOST_CHECK( b.origin()[2] == 3 );
	BOOST_CHECK( b.direction()[0] == 4 );
	BOOST_CHECK( b.direction()[1] == 5 );

	b.swap(a);

	BOOST_CHECK( a.origin()[0] == 1 );
	BOOST_CHECK( a.origin()[1] == 2 );
	BOOST_CHECK( a.origin()[2] == 3 );
	BOOST_CHECK( a.direction()[0] == 4 );
	BOOST_CHECK( a.direction()[1] == 5 );
	BOOST_CHECK( b.origin()[0] == 0 );
	BOOST_CHECK( b.origin()[1] == 0 );
	BOOST_CHECK( b.origin()[2] == 0 );
	BOOST_CHECK( b.direction()[0] == 0 );
	BOOST_CHECK( b.direction()[1] == 0 );
}

BOOST_AUTO_TEST_CASE( line3d__origin )
{
	sgl::line<3> a;

	BOOST_CHECK( a.origin()[0] == 0 );
	BOOST_CHECK( a.origin()[1] == 0 );
	BOOST_CHECK( a.origin()[2] == 0 );

	a.origin()[0] = 1;
	a.origin()[1] = 1;
	a.origin()[2] = 1;

	BOOST_CHECK( a.origin()[0] == 1 );
	BOOST_CHECK( a.origin()[1] == 1 );
	BOOST_CHECK( a.origin()[2] == 1 );
}

BOOST_AUTO_TEST_CASE( line3d__direction )
{
	sgl::line<3> a;

	BOOST_CHECK( a.direction()[0] == 0 );
	BOOST_CHECK( a.direction()[1] == 0 );

	a.direction()[0] = 1;
	a.direction()[1] = 1;

	BOOST_CHECK( a.direction()[0] == 1 );
	BOOST_CHECK( a.direction()[1] == 1 );
}

BOOST_AUTO_TEST_CASE( line3d__geometric_type )
{
	sgl::line<3> a;

	BOOST_CHECK( a.type() == sgl::geometric_primitive<>::line );
}

BOOST_AUTO_TEST_CASE( line3d__dimensions )
{
	sgl::line<3> a;

	BOOST_CHECK( a.dimensions() == 3 );
}

BOOST_AUTO_TEST_CASE( line3d__operator_minus )
{
	sgl::line<3> a;
	sgl::line<3> b = -a;

	BOOST_CHECK( b.origin()[0] == 0 );
	BOOST_CHECK( b.origin()[1] == 0 );
	BOOST_CHECK( b.origin()[2] == 0 );
	BOOST_CHECK( b.direction()[0] == M_PI );
	BOOST_CHECK( b.direction()[1] == M_PI );
}

BOOST_AUTO_TEST_CASE( line3d__operator_equality )
{
	sgl::line<3> a;
	sgl::line<3> b;

	BOOST_CHECK( a == b );

	sgl::line<3> c(sgl::point<3>(1, 2, 3), sgl::direction<3>(4, 5));
	sgl::line<3> d(sgl::point<3>(1, 2, 3), sgl::direction<3>(4, 5));

	BOOST_CHECK( c == d );
}

BOOST_AUTO_TEST_CASE( line3d__operator_inequality )
{
	sgl::line<3> a;
	sgl::line<3> b(sgl::point<3>(1, 2, 3), sgl::direction<3>(4, 5));

	BOOST_CHECK( a != b );
}

BOOST_AUTO_TEST_CASE( line3d__addition )
{
	sgl::line<3> a;
	a += sgl::vector<3>(1, 2, 3);

	BOOST_CHECK( a.origin()[0] == 1 );
	BOOST_CHECK( a.origin()[1] == 2 );
	BOOST_CHECK( a.origin()[2] == 3 );
	BOOST_CHECK( a.direction()[0] == 0 );
	BOOST_CHECK( a.direction()[1] == 0 );

	sgl::line<3> b;
	sgl::vector<3> c(1, 2, 3);
	sgl::line<3> d = b+c;

	BOOST_CHECK( d.origin()[0] == 1 );
	BOOST_CHECK( d.origin()[1] == 2 );
	BOOST_CHECK( d.origin()[2] == 3 );
	BOOST_CHECK( d.direction()[0] == 0 );
	BOOST_CHECK( d.direction()[1] == 0 );

	sgl::line<3> e = c+b;

	BOOST_CHECK( e.origin()[0] == 1 );
	BOOST_CHECK( e.origin()[1] == 2 );
	BOOST_CHECK( e.origin()[2] == 3 );
	BOOST_CHECK( e.direction()[0] == 0 );
	BOOST_CHECK( e.direction()[1] == 0 );
}

BOOST_AUTO_TEST_CASE( line3d__subtraction )
{
	sgl::line<3> a;
	a -= sgl::vector<3>(1, 2, 3);

	BOOST_CHECK( a.origin()[0] == -1 );
	BOOST_CHECK( a.origin()[1] == -2 );
	BOOST_CHECK( a.origin()[2] == -3 );
	BOOST_CHECK( a.direction()[0] == 0 );
	BOOST_CHECK( a.direction()[1] == 0 );

	sgl::line<3> b;
	sgl::vector<3> c(1, 2, 3);
	sgl::line<3> d = b-c;

	BOOST_CHECK( d.origin()[0] == -1 );
	BOOST_CHECK( d.origin()[1] == -2 );
	BOOST_CHECK( d.origin()[2] == -3 );
	BOOST_CHECK( d.direction()[0] == 0 );
	BOOST_CHECK( d.direction()[1] == 0 );
}

BOOST_AUTO_TEST_SUITE_END()

